import deluge.common, deluge.pref, gtk, gtk.glade, feedparser

class plugin_GATS:
    def __init__(self, path, deluge_core, deluge_interface):
        self.path = path
        self.core = deluge_core
        self.interface = deluge_interface
        self.config = deluge.pref.Preferences()
        
        self.path_icon = self.path + "/rss.png" # fixme less ambiguous icon
        
        # load configuration
        self.path_shows = deluge.common.CONFIG_DIR + "/gats_shows.conf"
        try:
            self.config.load(self.path_shows)
        except IOError:
            pass
        
        # toolbar button
        icon = gtk.Image()
        icon.set_from_file(self.path_icon)
        self.button = gtk.ToolButton(icon_widget=icon, label="TV Shows")
        self.button.connect("clicked", self.toolbar_clicked)
        self.interface.toolbar.add(self.button)
        self.button.show_all()
        
        # load configuration interface
        self.glade = gtk.glade.XML(path + "/gats.glade")
        self.win_shows = self.glade.get_widget("win_shows")
        self.win_shows.set_icon_from_file(self.path_icon)
    
    def toolbar_clicked(self,button):
        # fixme update contents of the showlist
        self.win_shows.show()
    
    def unload(self):
        self.interface.toolbar.remove(self.button)
        self.config.save(self.path_shows)
    
    def update(self):
        # fixme update feeds
        pass
